<!DOCTYPE html>

<html>
<head>
	<title>芭蕉花后台管理系统</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="SHORTCUT ICON" href="/img/favicon.ico">
	<script type="text/javascript">
		// 判断手机浏览
		var pathname = window.location.pathname;
		if (isMobile()) {
			if (pathname != "/mobile/home.html") {
				location.href = '/mobile/home.html';
			}
		} else {
			if (pathname != "/home.html") {
				location.href = '/home.html';
			}
		}
	
		function isMobile() {
			if (window.navigator.userAgent
					.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
				return true; // 移动端
			} else {
				return false; // PC端
			}
		}
	</script>
	<script src="pages/commonCss.js"></script>
	<script src="pages/commonJs.js"></script>
</head>
<style type="text/css">
	#menuFrame {
		width: 100%;
		min-height: 835px;
	}

	#systemConfig {
		position: absolute;
		right: 0%;
		top: 100%;
		background: #fff;
		list-style: none;
		text-align: center;
		padding: 10px 40px;
		display: none;
	}

	#systemConfig li {
		padding: 8px 0;
		font-size: 16px;
	}
</style>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
	<!-- 头部 -->
	<header class="main-header">
		<!-- Logo -->
		<a href="#" class="logo">
            <span class="logo-mini">
                <img alt="" src="/img/logo.png" id="logos" width="40px" height="40px" onclick="reflash()">
            </span>
			<span class="logo-lg" onclick="reflash()"><b>芭蕉花管理平台</b></span>
		</a>

		<!-- Header Navbar -->
		<nav class="navbar navbar-static-top" >
			<!-- Sidebar toggle button-->
			<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
				<span class="sr-only">芭蕉花管理平台</span>
			</a>


			<!-- Navbar Right Menu -->
			<div class="navbar-custom-menu">
				<ul class="nav navbar-nav">
					<li class="dropdown user user-menu">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <span class="hidden-xs">
							<i class="fa fa-fw fa-user"></i>
                            <span style="font-size: 18px;" id="currentUser"></span>
                        </span>
						</a>

					</li>

					<li onclick="systemConfigShow();"><a href="#" data-toggle="control-sidebar"><i
							class="fa fa-gear"></i></a></li>

					<ul id="systemConfig" class="systemConfigClass">
						<li><a href="pages/admin/changePassword.html" style="color: black;" target="menuFrame">修改密码</a></li>
						<li><a href="/logout" style="color: black;">退出登录</a></li>
					</ul>

				</ul>
			</div>
		</nav>
	</header>

	<!-- 左边栏 -->
	<aside class="main-sidebar">
		<section class="sidebar">
			<ul class="sidebar-menu" id="menuIds" data-widget="tree">
			</ul>
		</section>
	</aside>

	<!-- 内容显示部分 -->
	<div class="content-wrapper">
		<iframe id="menuFrame" name="menuFrame" src="/pages/welcome.html" width="100%" height=100% frameborder="0" marginheight="0" marginwidth="0" >
		</iframe>
	</div>

	<!-- 底部 -->
	<footer class="main-footer">
		<!-- To the right -->
		<div class="pull-right hidden-xs"></div>
		<!-- Default to the left -->
		<strong id="copyright"></span>
		</strong>
	</footer>

</div>
</body>
<script type="text/javascript">
	var sessionId = "";
	// 初始化
	$(function () {
		initSysInfo();
		initMenu();
		getBasicInfo();
	});
	//初始化基本信息
	function getBasicInfo() {
		$.ajax({
			type : 'post',
			url : '/sys/getAdminSysInfo',
			success : function(res) {
				var res = res.data;
				var str = "";
				for (var i = 0; i <res.length ; i++) {
					if(res[i].keys == 'copyright'){
						str += res[i].value;
					}
				}
				for (var i = 0; i <res.length ; i++) {
					if(res[i].keys == 'company'){
						str += " ";
						str += res[i].value;
					}
					if(res[i].keys == 'logo'){
						$("#logos").attr("src",res[i].value);
					}
				}
				$("#copyright").text(str);
			},
		});
	}

	//初始化账号信息
	function initSysInfo() {
		$.ajax({
			url: "/sys/getLoginInfo",
			type: "post",
			async: false,
			success: function (data) {
				$("#currentUser").text(data.data.userInfo.nickName);
				sessionId = data.data.sessionId;
			}
		});
	}
	//加载菜单
	function initMenu() {
		var menu = null;
		var html = null;
		var chidLen = null;
		var child = null;

		$.ajax({
			url: "/sysmenu/menuList",
			type: "post",
			async: false,
			success: function (data) {
				var menuJson = data.data.menuList;
				if (!$.isArray(menuJson)) {
					location.href = '/login.html';
					return;
				}

				for (var i = 0; i < menuJson.length; i++) {
					var html = "";
					menu = menuJson[i];
					// if(i==0){
					// 	html = $(' <li menu-id="' + i + '" class="active treeview "><li>');
					// }else{
					// 	html = $(' <li menu-id="' + i + '" class="treeview "><li>');
					// }
					html = $(' <li menu-id="' + i + '" class="treeview " ><li>');

					$("#menuIds").append(html);
					html = $(' <a href="'+menu.url+'" target="menuFrame"> <i class="'+menu.icon+'"></i> <span>'+menu.name+'</span> <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a> <ul menuUl-id="'+i+'" class="treeview-menu"> </ul>');
					chidLen = menu.child.length;

					$('[menu-id="'+i+'"]').append(html);
					for (var j=0;j<chidLen;j++){
						child = menu.child[j];
						let herf = "";
						if (child.host != null && child.host != '') {
							herf += child.host + "/";
						}
						herf += child.url;
						if (child.host != null && child.host != '') {
							herf += "?sessionId=" + sessionId;
						}
						if(i==0&&j==0){
							html = $('<li class=""><a href="'+herf+'" target="menuFrame"><i class="'+child.icon+'"></i> '+child.name+'</a></li>');
						}else{
							html = $('<li class=""><a href="'+herf+'" target="menuFrame"><i class="'+child.icon+'"></i> '+child.name+'</a></li>');
						}

						$('[menuUl-id="'+i+'"]').append(html);
					}
				}
				$(".sidebar-menu li:first ul li:first a").click();
			}
		});
	}
	
	function reflash() {
		location.reload();
	}

	//设置右上角菜单是否显示
	var showOrNot = true;
	function systemConfigShow(){
		if(showOrNot){
			$("#systemConfig").show();
			showOrNot = false;
		}else{
			$("#systemConfig").hide();
			showOrNot = true;
		}
	}
	//系统设置菜单点击事件
	$(".systemConfigClass li").click(function(){
		$("#systemConfig").hide();
		showOrNot = true;
	});

	setInterval(function(){
		checkLogin(function(result) {
			if (result != "success") {
				location.href = '/login.html';
			}
		});
	}, 60000);

	// 检查登录状态
	function checkLogin(callback) {
		$.ajax({
			type : 'post',
			url : '/sys/getLoginInfo',
			async : false,
			success : function(data) {
				callback("success");
			},
			error : function(xhr, textStatus, errorThrown) {
				callback("error");
			}
		});
	}
</script>

</html>